<template>
  <div class="audition174">
    <p>通过继承Array，并重写Array中的方法来实现监测</p>
    <v-md-preview :text="text1" />
  </div>
</template>

<script>
const prefix = '``` js'
const suffix = '```'
export default {
  name: 'Audition174',
  data() {
    return {
      text1: `${prefix}
      class NewArray extends Array {
        constructor(...args) {
          super(...args)
        }
        push(...args) {
          console.log('监听到数组发生变化啦！')
          return super.push(...args)
        }
      }
      let arr = [1, 2, 3]
      let arr1 = new NewArray(...arr)
      arr1.push('hello')
      console.log(arr1)
      \n${suffix}`,
    }
  }
}
</script>

<style>

</style>